`
https://leetcode.cn/problems/grumpy-bookstore-owner/
`

/**
 * @param {number[]} customers
 * @param {number[]} grumpy
 * @param {number} minutes
 * @return {number}
 */
var maxSatisfied = function (customers, grumpy, minutes) {
  const n = customers.length
  // sum[0] 表示满意的人数，sum[1] 表示不满意的人数
  const sum = [0, 0]
  let maxS1 = 0
  let left = 0, right = 0

  // 维护一个长度为 minutes 的滑动窗口
  while (right < n) {
    const n1 = customers[right]
    const isGrumpy = grumpy[right]
    right++
    sum[isGrumpy] += n1

    if (right - left >= minutes) {
      // 只要更新窗口内不满意的人数即可
      maxS1 = Math.max(maxS1, sum[1])
      const n2 = customers[left]
      const isLeftGrumpy = grumpy[left]
      left++
      if (isLeftGrumpy) {
        sum[isLeftGrumpy] -= n2
      }
    }
  }

  // 最后把总的满意人数 + 能变成满意的最多人数
  return sum[0] + maxS1
};